<script>
	import { usePublicStore } from './store/public';
	export default {
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show1')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			baseUrl:'http://localhost:8081',
			zuZhuId:'1',
		},
		methods: {
		    checkAuth() {
		      const requiredKeys = ['token','tenantId', 'type'];
		      const currentRoute = getCurrentPages().pop()?.route || '';
		      
		      // 排除登录页本身，避免循环跳转
		      if (currentRoute.includes('login')) return;
		      
		      // 检查所有必要字段
		      const missingKeys = requiredKeys.filter(key => !uni.getStorageSync(key));
			  console.log('test')
			  console.log(uni.getStorageSync('token'))
			  console.log(uni.getStorageSync('tenantId'))
			  console.log(uni.getStorageSync('type'))
		      
		      if (missingKeys.length > 0) {
		        console.warn('缺失的存储字段:', missingKeys);
		        uni.reLaunch({
		          url: '/pages/login/login' // 跳转到登录页
		        });
		      }
		    }
		},
		onLaunch() {
			console.log('App Launch')
		    this.checkAuth();
			this.$nextTick(() => {
			    usePublicStore().updateUserInfo();
			  });
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>
